/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-08-04
 * Time: 22:01
 */
public class test3 {
    public ListNode swapPairs(ListNode head) {
        if(head==null || head.next==null){
            return head;
        }
        ListNode pre = new ListNode(0);
        pre.next = head;
        ListNode tmp = pre;
        while(tmp.next!=null && tmp.next.next!=null){
            // head
            ListNode slow = tmp.next;
            // head.next
            ListNode fast = tmp.next.next;
            // 进行交换
            tmp.next = fast;
            slow.next = fast.next;
            fast.next = slow;
            // 交换完了进行移动
            tmp = slow;
        }
        return pre.next;
    }

    class ListNode{
        int val;
        ListNode next;

        public ListNode(int val){
            this.val = val;
        }
    }
}
